﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

namespace mpsalary
{
    public partial class Signup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ddlSalutation.SelectedValue.Equals("Ms"))
            {
                lblGender.Text = "Female";
            }
            else if (ddlSalutation.SelectedValue.Equals("Mrs"))
            {
                lblGender.Text = "Female";
            }
            else if (ddlSalutation.SelectedValue.Equals("Mr"))
            {

                lblGender.Text = "Male";
            }
            else if (ddlSalutation.SelectedValue.Equals("Mdm"))
            {

                lblGender.Text = "Female";
            }

            if (!Page.IsPostBack)
            {

                String usename = (string)(Session["Usename"]);
                String emailaddress = (string)(Session["Email"]);
                mpsalary.App_Code.User user = new mpsalary.App_Code.User();
                tbxFirstName.Text = usename;
                tbxEmail.Text = emailaddress;
            }
            if (Page.IsPostBack)
            {
                //if user declare as student, company textbox will be unenabled
                //they don't need to key in anything in the textbox
                if (rblOccupation.SelectedValue.Equals("Student"))
                {
                    tbxCompany.Enabled = false;
                    CompanyValidator.Visible = false;
                    ddlSchool.Enabled = true;

                }
                //if user declare as a employee, student textbox will be unenabled
                //they don't need to key in anything in the textbox
                else if (rblOccupation.SelectedValue.Equals("Employee"))
                {
                    ddlSchool.Enabled = false;
                    SchoolValidator.Visible = false;
                }

                else if (rblOccupation.SelectedValue.Equals("Others"))
                {
                    ddlSchool.Enabled = false;
                    SchoolValidator.Visible = false;
                    tbxCompany.Enabled = false;
                    CompanyValidator.Visible = false;
                }
            }

            {
                if (!Page.IsPostBack)
                {
                    SetCaptchaText();
                }
                if (Session["Name"] != null)
                    tbxFirstName.Text = Session["Name"].ToString();
            }

            
        }
        private void SetCaptchaText()
        {
            Random oRandom = new Random();
            int iNumber = oRandom.Next(10000, 99999);
            Session["Captcha"] = iNumber.ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            tbxFirstName.ReadOnly = true; 
        }

        protected void imagebtnSubmit_Click(object sender, ImageClickEventArgs e)
        {
            

            mpsalary.App_Code.User user = new mpsalary.App_Code.User();

           user.Occupation = rblOccupation.SelectedValue;
            user.Usename = tbxFirstName.Text;
            user.Salutation = ddlSalutation.Text;
            user.Gender = lblGender.Text;
            user.NRIC = tbxNRIC.Text;
            user.Email = tbxEmail.Text;
            user.Password = tbxPassword.Text;
            user.MobileNo = tbxMobileNo.Text;

            user.UpdateUser();
        }

        
        //protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        //{
        //    Session["Name"] = tbxFirstName.Text;
        //    Response.Redirect("mainPage.aspx");
        //}

        //protected void imagebtnHome_Click(object sender, ImageClickEventArgs e)
        //{
        //    Response.Redirect("homePage.aspx");

        //}

        //protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        //{
        //    Response.Redirect("mainPage.aspx");

        //}

        //protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
        //{
            
        //}

    }
}